UIHeroRank = {}
HelperFunc.SetUIEnv(UIHeroRank)
local this = UIHeroRank;

this.LuaBehaviour = nil;
this.transform = nil;
this.gameObject = nil;
this.hasInit = nil;


--panel
this.btn_addLv = nil;
this.table_star ={}; --星级预设
this.table_starInfo ={}; --星级预设
this.txt_att_HP = nil; --血量文字
this.txt_att_Ack = nil;--攻击力
this.txt_att_Def = nil;
this.txt_att_Fight = nil;--战力
this.txt_att_HPUp = nil; --提升后预览血量
this.txt_att_AckUp = nil;
this.txt_att_DefUp = nil;
this.txt_att_FightUp = nil;

this.table_skill={} --技能预设
this.table_skillUp={}

---cache----
this.curHeroData = nil; --总数据
this.heroRankConfig = nil;
this.heroRankUpCo=nil
this.heroRankUpCoBase=nil
this.table_Cost={}
this.table_CostNum={}
this.curHeroAttribute = nil; --属性数据
this.heroConfig=nil; --英雄配置
this.tokenChipConfig=nil; --万能碎片表
this.hasInit = false;
this.sillUpInfo={}
this.Backbtn = nil;

this.btninfo = nil
this.btnBackInfo = nil;
this.btnPlayerRank = nil;
this.UImer = nil;
this.heroName = nil;
this.heroType = nil;
this.RoleLihui = nil;
this.needLevel = nil;
this.ChoseObj = nil;
this.SortingTab={}
this.costTab={}
this.RankUpID = nil
this.heroDataList = {}
this.canUpStar=true;
---@type GList
this.starList = nil
this.dynamicList = nil
---@type UIHeroRankPreview
this.uiHeroRankPreview = nil
---@type UIPlayerRankPanel
this.uiPlayerRankPanel = nil
---@type GController
this.ctrlPage = nil
this.ctrlChooseType = nil
---@type GoWrapper
this.goWrapper = nil
---@type GGraph
this.modelGraphic = nil
this.btnHeroRank = nil
this.curHeroId = nil
this.isPlayer = nil
function UIHeroRank.Init()
    local id = logicMgr.HeroManager.getOwnerHeroList(false,nil,true)[1].partnerId
    curHeroData= logicMgr.HeroManager.getHeroDatabyPartnerId(id,true)
    curHeroId = id
    curHeroAttribute=curHeroData["allAttribute"][1]
    local name,package = getUIName(PanelResNames.UIHeroRank);
    panelMgr:Push(name,package, this.onCreate,Config.useLocalUI);
    --panelMgr:ShowUI(name, this.onCreate,Config.useLocalUI);
end
---@param obj GComponent
function UIHeroRank.onCreate(obj)
    --gameObject = obj;
    --transform = obj.transform;
    --LuaBehaviour = transform:GetComponent('LuaBehaviour');
    if not hasInit then
        hasInit = true;
        uiHeroRankPreview = CtrlManager.GetCtrl(PanelNames.UIHeroRankPreview).New()
        uiHeroRankPreview:Bind(obj:GetChild("preview"),this.ClickClosePreview)
        uiPlayerRankPanel = CtrlManager.GetCtrl(PanelNames.UIPlayerRankPanel).New()
        uiPlayerRankPanel:Bind(obj:GetChild("main"))
        ctrlPage = obj:GetController("ctrlPage")
        ctrlChooseType = obj:GetController("ctrlChooseType")
        starList = obj:GetChild("starList")
        ctrlChooseType.onChanged:Add(this.ChoseTypeChanged)
        goWrapper = GoWrapper.New()
        modelGraphic = obj:GetChild("modelPos")

        local costpath = "title";
        for i = 1, 3 do
            local item = obj:GetChild("title"..i)
            local sun = item:GetChild("sun")
            local TextNum = item:GetChild("Text")
            table.insert(table_Cost, { go = item,icon = sun,num = TextNum});
        end

        btn_addLv = obj:GetChild("btnWeak")
        --btnBackInfo=obj:GetChild("UImercenary/backbg"):GetComponent("Button");
        btninfo=obj:GetChild("btninfo")
        btnPlayerRank =obj:GetChild("btnPlayerRank")
        btnHeroRank = obj:GetChild("btnHeroRank")
        Backbtn=obj:GetChild("Backbtn")
        heroName=obj:GetChild("NameLb"):GetChild("title")
        heroType=obj:GetChild("NameLb"):GetChild("opType");
        --UImer=transform:Find("UImercenary").gameObject

        dynamicList=obj:GetChild("itemGrid")
        needLevel=obj:GetChild("needLevel")
        dynamicList.itemRenderer = this.SetData
        this.addEvent();
    end
    ctrlChooseType.selectedIndex = 0
    ctrlPage.selectedIndex = 0
    isPlayer = false
    this.ShowHero(logicMgr.HeroManager.getOwnerHeroList(nil,nil,true));
    --SortingTab[7].isOn=true;
    this.initData();
    --this.initHeroInfo();
    --this.onInitHeroEquip();
end

function UIHeroRank.initData()
    local tempStar=curHeroData["star"]
    local serchID=curHeroData["partnerModelId"]*10+tempStar
    heroRankConfig=G.dataTable["t_herorank"][tostring(serchID)]
    RankUpID=tempStar
    heroRankUpCoBase=G.dataTable["t_herorankupco"][tostring(RankUpID)]
    if(heroRankConfig.f_HeroStarNext~=0 and tempStar< logicMgr.HeroManager.LimitStar() )then
        RankUpID=G.dataTable["t_herorank"][tostring(heroRankConfig.f_HeroStarNext)].f_HeroStar;
    end
    heroRankUpCo=G.dataTable["t_herorankupco"][tostring(RankUpID)]
    this.initHeroInfo()
    this.initSkill(RankUpID)
end

function UIHeroRank.addEvent()
    for k, v in pairs(table_Cost) do
        v.go.onClick:Add(function()  this.onClickitem(k); end )
    end
    btn_addLv.onClick:Add(this.onClickUpLevel)
    btninfo.onClick:Add(this.OpenInfo)
    btnPlayerRank.onClick:Add(this.ClickChangePlayer)
    btnHeroRank.onClick:Add(this.ClickChangeHero)
    Backbtn.onClick:Add(this.CloseRank)
    --[[for i = 1, 7 do
        SortingTab[i].onValueChanged:AddListener(function(isOn) this.onClickType(isOn,i) end)
    end
    for i = 1, 3 do
        LuaBehaviour:AddClick(table_Cost[i].transform.parent.gameObject,function()  this.onClickitem(i); end );
    end
    LuaBehaviour:AddClick(btn_addLv.gameObject, this.onClickUpLevel);
    LuaBehaviour:AddClick(btninfo.gameObject, this.OpenInfo);
    LuaBehaviour:AddClick(btnBackInfo.gameObject, this.CloseInfo);
    LuaBehaviour:AddClick(btnChangeHero.gameObject, this.OpenHero);
    LuaBehaviour:AddClick(Backbtn.gameObject, this.CloseRank);]]
end

function UIHeroRank.removeEvent()
    for k, v in pairs(table_Cost) do
        v.go.onClick:Clear()
    end
    btn_addLv.onClick:Clear()
    btninfo.onClick:Clear()
    btnPlayerRank.onClick:Clear()
    btnHeroRank.onClick:clear()
    Backbtn.onClick:Clear()
    --[[for i = 1, 7 do
        SortingTab[v].onValueChanged:RemoveAllListeners()
    end
    for i = 1, 3 do
        LuaBehaviour:RemoveClick(table_Cost[i].transform.parent.gameObject.gameObject);
    end
    LuaBehaviour:RemoveClick(btn_addLv.gameObject);
    LuaBehaviour:RemoveClick(btninfo.gameObject);
    LuaBehaviour:RemoveClick(btnBackInfo.gameObject);
    LuaBehaviour:RemoveClick(btnChangeHero.gameObject);
    LuaBehaviour:RemoveClick(Backbtn.gameObject);]]
end

function UIHeroRank.onClickitem(index)
    local IDs=costTab[tostring(index)]
    if(IDs~=nil)then
        local data={}
        data=logicMgr.ItemManager.getItemConstDatabyModelId(IDs);
        showUI(PanelNames.UIBagItemInfo,data);
    end
end

function UIHeroRank.onClickUpLevel()
    if(curHeroData["star"]>=logicMgr.HeroManager.LimitStar())then
        UISysTips.AddMsg(getLanguage("Sys_HeroFullRank"));
        return;
    end
    if(logicMgr.HeroManager.GetRoleLevel()< heroRankConfig.f_RankUpLimit)then
        local unlockStr=getLanguage("TacticalUi_1")..getLanguage("TacticalUi_7")
        unlockStr=string.format(unlockStr, tostring(heroRankConfig.f_RankUpLimit))
        UISysTips.AddMsg(unlockStr);
        return;
    end

    if(canUpStar==false)then
        UISysTips.AddMsg(getLanguage("ErrorCode_1"));
        return;
    end
    if(heroRankConfig.f_HeroStarNext==0)then
        UISysTips.AddMsg(getLanguage("ErrorCode_70"));
        return;
    end
    --local rwms=G.serverData["roleInfo"]

    partnerHandler.sendUpStarMessage(curHeroData["partnerId"],ItemManager.getItemCountbyModelId(curHeroData.storeId))
end

function UIHeroRank.LocalListenEvent()
    ListenEvent(Config.EventType.Fresh_Star,this.updateHeroStar);
end

function UIHeroRank.LocalCloseEvent()
    CloseEvent(Config.EventType.Fresh_Star,this.updateHeroStar);
end

function UIHeroRank.OnDestroy()
    this.removeEvent();
    uiHeroRankPreview:OnDestroy()
    uiPlayerRankPanel:OnDestroy()
    destroy(RoleLihui)
    RoleLihui = nil
    destroyGoWraper(goWrapper)
    goWrapper = nil
end

function UIHeroRank.OnEnable()
    this.LocalListenEvent();
end

function UIHeroRank.OnDisable()
    this.LocalCloseEvent();
end

function UIHeroRank.CloseRank()
    closeUI(PanelNames.UIHeroRank);
end

function UIHeroRank.OpenInfo()
    --UImer:SetActive(true);
end

function UIHeroRank.CloseInfo()
    --UImer:SetActive(false);
end

function UIHeroRank.ClickChangePlayer()
    --closeUI(PanelNames.UIHeroRank);
    --panelMgr:CloseUI("UIHeroRank",true);
    --showUI(PanelNames.UIPlayerRank,logicMgr.HeroManager.getMyself().partnerId);
    isPlayer = true
    this.changeheadById(logicMgr.HeroManager.getMyself().partnerId)

end
function UIHeroRank.ClickChangeHero()
    --ctrlPage.selectedIndex = 0
    isPlayer = false
    this.changeheadById(curHeroId)
end
--消息返回后重新更新数据
function UIHeroRank.updateHeroStar()
    curHeroData= logicMgr.HeroManager.getHeroDatabyPartnerId(curHeroData["partnerId"],true)
    curHeroAttribute=curHeroData["allAttribute"][1]
    local tempStar=curHeroData["star"]
    local serchID=curHeroData["partnerModelId"]*10+tempStar
    heroRankConfig=G.dataTable["t_herorank"][tostring(serchID)]
    RankUpID=tempStar
    if(heroRankConfig.f_HeroStarNext~=0)then
        RankUpID=G.dataTable["t_herorank"][tostring(heroRankConfig.f_HeroStarNext)].f_HeroStar;
    end
    heroRankUpCo=G.dataTable["t_herorankupco"][tostring(RankUpID)]
    this.initHeroInfo()
    this.initSkill(RankUpID)
end

--更新技能解锁数据
function UIHeroRank.initSkill(nowStar)
    sillUpInfo={}
    if(heroConfig.f_HeroSkill1~=nil)then
        local tempSkillInfo=logicMgr.SkillManager.getSkillInfoConfig(heroConfig.f_HeroSkill1)
        if tempSkillInfo then
            local skillupStar= decodeJsonStrToTabel(tempSkillInfo.f_LevelRequireRank);
            local skillupLevel=decodeJsonStrToTabel(tempSkillInfo.f_SkillLevel);
            for i = 1, #skillupStar do
                if(nowStar==skillupStar[i])then
                    local skillUpData={}
                    skillUpData.id=heroConfig.f_HeroSkill1
                    skillUpData.level=skillupLevel[i]
                    table.insert( sillUpInfo,skillUpData);
                end
            end
        end
    end
    if(heroConfig.f_HeroSkill2~=nil)then
        local tempSkillInfo=logicMgr.SkillManager.getSkillInfoConfig(heroConfig.f_HeroSkill2)
        local skillupStar= decodeJsonStrToTabel(tempSkillInfo.f_LevelRequireRank);
        local skillupLevel=decodeJsonStrToTabel(tempSkillInfo.f_SkillLevel);
        for i = 1, #skillupStar do
            if(nowStar==skillupStar[i])then
                local skillUpData={}
                skillUpData.id=heroConfig.f_HeroSkill1
                skillUpData.level=skillupLevel[i]
                table.insert( sillUpInfo,skillUpData);
            end
        end
    end
    if(heroConfig.f_HeroSkill3~=nil)then
        local tempSkillInfo=logicMgr.SkillManager.getSkillInfoConfig(heroConfig.f_HeroSkill3)
        local skillupStar= decodeJsonStrToTabel(tempSkillInfo.f_LevelRequireRank);
        local skillupLevel=decodeJsonStrToTabel(tempSkillInfo.f_SkillLevel);
        for i = 1, #skillupStar do
            if(nowStar==skillupStar[i])then
                local skillUpData={}
                skillUpData.id=heroConfig.f_HeroSkill1
                skillUpData.level=skillupLevel[i]
                table.insert( sillUpInfo,skillUpData);
            end
        end
    end
    if(heroConfig.f_HeroSkill4~=nil)then
        local tempSkillInfo=logicMgr.SkillManager.getSkillInfoConfig(heroConfig.f_HeroSkill4)
        local skillupStar= decodeJsonStrToTabel(tempSkillInfo.f_LevelRequireRank);
        local skillupLevel=decodeJsonStrToTabel(tempSkillInfo.f_SkillLevel);
        for i = 1, #skillupStar do
            if(nowStar==skillupStar[i])then
                local skillUpData={}
                skillUpData.id=heroConfig.f_HeroSkill1
                skillUpData.level=skillupLevel[i]
                table.insert( sillUpInfo,skillUpData);
            end
        end
    end
    uiHeroRankPreview:RefreshSkill(sillUpInfo)
    --[[for i = 1, #table_skill do
        table_skill[i].gameObject:SetActive(false)
        table_skillUp[i].gameObject:SetActive(false)
    end
    for i = 1, #sillUpInfo do
        local thisSkill=sillUpInfo[i]
        local skillIconSpr=nil
        if(thisSkill.level==1)then
            skillIconSpr=table_skill[i]
            skillIconSpr.transform.parent.gameObject:SetActive(true);
        else
            skillIconSpr=table_skillUp[i]
            skillIconSpr.transform.parent.gameObject:SetActive(true);
        end
        skillIconSpr.gameObject:SetActive(true)
        local tempSkillinfo=logicMgr.SkillManager.getSkillInfoConfig(thisSkill.id);--"12002"
        resMgr:LoadIconFromPrefab("skillAtlas",tempSkillinfo.f_SkillIcon,function(iconstr)
            skillIconSpr.sprite = iconstr;
        end);

        skillIconSpr.transform:Find("RankingTips"):GetComponent("TextMeshProUGUI").text=getLanguage(tempSkillinfo.f_SkillName)..thisSkill.level;

    end]]
end

--更新英雄数据
function UIHeroRank.initHeroInfo()
    --UImer:SetActive(false);
    heroName.text=curHeroData.name;
    heroType.url = EnumConst.AtlasPath.HeroRankAtlas..Config.typeName[curHeroData.type]
    --resMgr:LoadIconFromPrefab("HeroRankAtlas",Config.typeName[curHeroData.type],function(go)
    --    heroType.sprite = go;
    --end)   
        

    resMgr:LoadModelPrefab(curHeroData.draw,function(go)
        if(RoleLihui~=nil)then
            destroyImmediate(RoleLihui);
            RoleLihui=nil;
        end
        RoleLihui= newObject(go);
        RoleLihui:AddComponent(TCanvas)
        goWrapper:SetWrapTarget(RoleLihui,false)
        modelGraphic:SetNativeObject(goWrapper)
        Util.Lua_SetLocalPositionXYZ(RoleLihui.transform,0,0,0);
        Util.AddAction(RoleLihui.gameObject,"idle1",true,0.5);
    end)
    if(heroRankConfig.f_RankUpLimit<=logicMgr.HeroManager.GetRoleLevel())then
        needLevel.text="";
    else
        local unlockStr=getLanguage("TacticalUi_1")..getLanguage("TacticalUi_7")
        unlockStr=string.format(unlockStr, tostring(heroRankConfig.f_RankUpLimit))
        needLevel.text=unlockStr;
    end

    canUpStar=true;
    heroConfig=G.dataTable["t_hero"][tostring(curHeroData["partnerModelId"])];
    for i = 1, 3 do
        table_Cost[i].go.visible = false
    end
    costTab={}
    if(heroRankConfig.f_RankItemCost~="")then
        --英雄需要消耗道具
        local Costtab=decodeJsonStrToTabel(heroRankConfig.f_RankItemCost)
        for i=1,#Costtab do
            costTab["3"]=Costtab[i][1]
            if(i<=3)then
                table_Cost[3].go.visible = true
                table_Cost[3].icon.url = EnumConst.AtlasPath.ItemAtlas..G.dataTable["t_item"][ tostring(Costtab[i][1])].f_Icon
                --resMgr:LoadIconFromPrefab("ItemAtlas",G.dataTable["t_item"][ tostring(Costtab[i][1])].f_Icon,function(iconstr)
                --    table_Cost[3].sprite = iconstr;
                --end);
                local tempheroCostNum=logicMgr.ItemManager.getItemCountbyModelId(Costtab[i][1]) or 0
                local Numstr=tostring(tempheroCostNum)
                if(tempheroCostNum>10000)then
                    Numstr=tostring(math.floor(tempheroCostNum/1000)).."k";
                end
                local needCost=Costtab[i][2]
                if(tempheroCostNum>=needCost)then
                    table_Cost[3].num.text="<color=green>"..Numstr.."</color>".."/"..needCost
                else
                    canUpStar=false;
                    table_Cost[3].num.text="<color=red>"..Numstr.."</color>".."/"..needCost
                end
            end
        end
        local Chiptab=decodeJsonStrToTabel(heroRankConfig.f_RankChipCost)
        local cutChip=0;
        table_Cost[2].go.visible = true;
        --ChipCostObj.transform.parent.gameObject:SetActive(true)
        costTab["2"]=Chiptab[1]
        table_Cost[2].icon.url = EnumConst.AtlasPath.ItemAtlas..G.dataTable["t_item"][ tostring(Chiptab[1])].f_Icon
        --resMgr:LoadIconFromPrefab("ItemAtlas",G.dataTable["t_item"][ tostring(Chiptab[1])].f_Icon,function(iconstr)
        --    ChipCostObj.sprite = iconstr;
        --end);
        local tempherochipNum=logicMgr.ItemManager.getItemCountbyModelId(Chiptab[1]) or 0
        local tempCostChip=Chiptab[2]
        if(tempherochipNum>=tempCostChip)then
            table_Cost[2].num.text="<color=green>"..tempherochipNum.."</color>".."/"..tempCostChip;
        else
            cutChip=tempCostChip-tempherochipNum
            table_Cost[2].num.text="<color=red>"..tempherochipNum.."</color>".."/"..tempCostChip;
        end

        --local heroConfigStar=heroConfig.f_HeroInitialStar
        --tokenChipConfig=G.dataTable["t_tokenchip"][tostring(heroConfigStar)]
        --
        --table_Cost[1].go.visible = true;
        ----tokenChipCostObj.transform.parent.gameObject:SetActive(true)
        --costTab["1"]=tokenChipConfig.f_ItemID
        --table_Cost[1].icon.url = EnumConst.AtlasPath.ItemAtlas..G.dataTable["t_item"][ tostring(tokenChipConfig.f_ItemID)].f_Icon
        ----resMgr:LoadIconFromPrefab("ItemAtlas",G.dataTable["t_item"][ tostring(tokenChipConfig.f_ItemID)].f_Icon,function(iconstr)
        ----    tokenChipCostObj.sprite = iconstr;
        ----end);
        --local mytokenChip=logicMgr.ItemManager.getItemCountbyModelId(tokenChipConfig.f_ItemID)
        --if(mytokenChip>=cutChip)then
        --    table_Cost[1].num.text="<color=green>"..mytokenChip.."</color>".."/"..cutChip;
        --else
        --    table_Cost[1].num.text="<color=red>"..mytokenChip.."</color>".."/"..cutChip;
        --end

        --if (mytokenChip+tempherochipNum)<tempCostChip then
        --    canUpStar=false;
        --end
    end
    uiHeroRankPreview:RefreshAttr(curHeroData,RankUpID)
    if ctrlPage.selectedIndex == 1 then
        uiPlayerRankPanel:Refresh()
    end
    --[[local baseData=clone(curHeroData)
    logicMgr.HeroManager.processHeroBaseAttr(baseData,curHeroData.level,RankUpID)
    txt_att_HP.text = curHeroAttribute[EnumConst.FighterAttributeEnum.HP];
    txt_att_Ack.text = curHeroAttribute[EnumConst.FighterAttributeEnum.ATK];
    txt_att_Def.text = curHeroAttribute[EnumConst.FighterAttributeEnum.DEF];
    txt_att_Fight.text = curHeroData["power"]
    local attbase=baseData.allAttribute[EnumConst.AttributeTypeEnum.BASE]
    txt_att_HPUp.text = attbase[EnumConst.FighterAttributeEnum.HP];
    txt_att_AckUp.text =attbase[EnumConst.FighterAttributeEnum.ATK];
    txt_att_DefUp.text =attbase[EnumConst.FighterAttributeEnum.DEF];
    --txt_att_FightUp.text= math.ceil(curHeroData["power"]*rate)
    attbase=nil
    baseData=nil]]
    local willStar=curHeroData["star"]
    if(heroRankConfig.f_HeroStarNext~=0)then
        willStar=G.dataTable["t_herorank"][tostring(heroRankConfig.f_HeroStarNext)].f_HeroStar;
    end
    local realStar=curHeroData["star"]
    local starcount =math.floor(realStar);
    for i = 1, starList.numItems do
        local child = starList:GetChildAt(i-1)
        child:GetController("cstar").selectedIndex = i<= starcount and 1 or 0
    end
    if(realStar-starcount>0)then
        local child = starList:GetChildAt(starcount)
        child.visible = true
        child:GetController("cstar").selectedIndex = 2
    end
    uiHeroRankPreview:RefreshStar(realStar)
    --[[for i = 1, #table_star do
        local child = starList:GetChildAt(i-1)
        table_star[i]:SetActive(i<= starcount)
        table_star[i]:GetComponent("Image").fillAmount=1
        table_starInfo[i]:SetActive(i<= starcount)
        table_starInfo[i]:GetComponent("Image").fillAmount=1
    end
    if(realStar-starcount>0)then
        table_star[starcount+1]:SetActive(true);
        table_star[starcount+1]:GetComponent("Image").fillAmount=0.5
        table_starInfo[starcount+1]:SetActive(true);
        table_starInfo[starcount+1]:GetComponent("Image").fillAmount=0.5
    end]]
    --this.onUpdatePower();
end

--[[function UIHeroRank.onClickType(isOn,index)
    if(index==7)then
        UIHeroRank.ShowHero(logicMgr.HeroManager.getOwnerHeroList(false))
    else
        local tempherolist=logicMgr.HeroManager.getOwnerHeroList(false);
        local tempsendLi={}
        for i = 1, #tempherolist do
            local tB=tempherolist[i]
            if(tB.type==index)then
                table.insert(tempsendLi,tB);
            end
        end
        UIHeroRank.ShowHero(tempsendLi)
    end
end]]
function UIHeroRank.ChoseTypeChanged()
    local index = ctrlChooseType.selectedIndex
    if(index==0)then
        UIHeroRank.ShowHero(logicMgr.HeroManager.getOwnerHeroList(nil,nil,true))
    else
        local tempherolist=logicMgr.HeroManager.getOwnerHeroList(false);
        local tempsendLi={}
        for i = 1, #tempherolist do
            local tB=tempherolist[i]
            if(tB.type==index)then
                table.insert(tempsendLi,tB);
            end
        end
        UIHeroRank.ShowHero(tempsendLi)
    end
end
function UIHeroRank.ShowHero(myHeroList)
    table.clear(heroDataList)
    for i = 1, #myHeroList do
        local itemValue={}
        local tempH=myHeroList[i]
        itemValue["partnerModelId"]=tempH.partnerModelId
        itemValue["partnerId"]=tempH.partnerId
        itemValue["star"]=tempH.star;
        itemValue["cube"]=1;
        table.insert(heroDataList,itemValue);
    end
    dynamicList.numItems = #heroDataList
    --local result = getJsonStr(table_banch);
    --dynamicList:setDataByJsonArray(result);
end

function UIHeroRank.SetData(index,itemobj)
    index = index+1
    local itemValue = heroDataList[index]
    local HeadRectDrawItem = CtrlManager.GetCtrl(PanelNames.HeadRectDrawItem);
    HeadRectDrawItem.initData(itemobj,itemValue);
    local gou=itemobj:GetChild("select");
    gou.visible = false;
    if(tostring(curHeroData.partnerId )==itemValue["partnerId"])then
        gou.visible = true
        ChoseObj=itemobj;
    end
    itemobj.onClick:Add(function()  this.changehead(itemValue["partnerId"],itemobj); end )
    --local itemValue =decodeJsonStrToTabel(datasource);
    --local HeadRectDrawItem = CtrlManager.GetCtrl(PanelNames.HeadRectDrawItem);
    --[[if HeadRectDrawItem ~= nil then
        HeadRectDrawItem.initData(itemobj,itemValue,LuaBehaviour);
        LuaBehaviour:RemoveClick(itemobj);
        local gou=itemobj.transform:Find("gou").gameObject;
        gou:SetActive(false);
        if(tostring(curHeroData.partnerId )==itemValue["partnerId"])then
            gou:SetActive(true);
            ChoseObj=itemobj;
        end
        LuaBehaviour:AddClick(itemobj, function()  this.changehead(itemValue["partnerId"],itemobj); end );
    end]]
end
function UIHeroRank.changeheadById(sendid)
    curHeroData= logicMgr.HeroManager.getHeroDatabyPartnerId(sendid)
    curHeroAttribute=curHeroData["allAttribute"][1]
    this.initData();
end
function UIHeroRank.changehead(sendid,obj)
    if(ChoseObj~=nil)then
        ChoseObj:GetChild("select").visible = false
    end
    ChoseObj=obj
    ChoseObj:GetChild("select").visible = true
    curHeroId = sendid
    this.changeheadById(sendid)
end

function UIHeroRank.onEquipCtrlSuccess()
    --this.onInitHeroEquip();
    --this.onUpdateAttribute();
end

function UIHeroRank.onUpdateUpStar()

end

function UIHeroRank.onUpdateAttribute()
    --local SerchKey=tostring(curHeroData["partnerModelId"]).."_"..tostring(curHeroData["level"]);
    --curHeroAttribute=decodeJsonStrToTabel(G.dataTable["T_character"][SerchKey].f_CharacterValue);
end
function UIHeroRank.ClickClosePreview()
    if isPlayer then
        ctrlPage.selectedIndex = 1
    else
        ctrlPage.selectedIndex = 0
    end

end
function UIHeroRank.onUpdatePower()
    local redio = 1;
    local powerConfig=nil
    if powerConfig == nil then
        powerConfig = G.dataTable["t_power"];
        redio = powerConfig[tostring(curHeroData["level"])].f_PowerCount;
    end

    if curHeroAttribute ~= nil then
        local attribute =curHeroAttribute;
        if attribute ~= nil then
            --[[战斗力=（属性3+5+6+7+8+9+14-15+16+17）*power表系数+属性2+属性4+（属性1/20)]]
            local sum = attribute[EnumConst.FighterAttributeEnum.BLOCK][2]
                    + attribute[EnumConst.FighterAttributeEnum.DODGE][2]
                    + attribute[EnumConst.FighterAttributeEnum.HITRATE][2]
                    + attribute[EnumConst.FighterAttributeEnum.CRITRATE][2]
                    + attribute[EnumConst.FighterAttributeEnum.CRITDAMAGE][2]
                    + attribute[EnumConst.FighterAttributeEnum.CRITRES][2]
                    + attribute[EnumConst.FighterAttributeEnum.CURE][2]
                    + attribute[EnumConst.FighterAttributeEnum.WEAK][2]
                    + attribute[EnumConst.FighterAttributeEnum.BUFF_HITRATE][2]
                    + attribute[EnumConst.FighterAttributeEnum.BUFF_DODGE][2];
            local power = sum * redio + attribute[EnumConst.FighterAttributeEnum.ATK][2] + attribute[EnumConst.FighterAttributeEnum.DEF][2]
                    + attribute[EnumConst.FighterAttributeEnum.HP][2]/20;
            txt_att_Fight.text = Mathf.Floor(power);
        end
    end
end




return UIHeroRank;
